#include "instructionscreen.h"
#include "ui_instructionscreen.h"

InstructionScreen::InstructionScreen(QWidget *parent, QString newFilepath) :
    QWidget(parent),
    ui(new Ui::InstructionScreen)
{
    //ui->setupUi(this);

    this->setGeometry(0, 0, 640, 640);
    this->filepath = newFilepath;

    //Create Background Image
    QString background = newFilepath + "Images/instructionsbg.png";
    qDebug() << "instruction screen background: " << background << endl;
    bg = QImage(background);

    //Load Font
    QFontDatabase::addApplicationFont(newFilepath + "Qubix.ttf");
    buttonFont = new QFont("Qubix", 28, -1, false);

    //Create Buttons
    back = new TextButton(this, "back", "white", "#29E0FF");
    back->setFont(*buttonFont);
    back->setGeometry(16, 6, 102, 34);  //With font size of 28, width is ((letters + spaces/2) * 25 + 2)
    connect(back, SIGNAL(clicked(QMouseEvent*)), this, SLOT(on_back_clicked()));
    back->show();
}

InstructionScreen::~InstructionScreen()
{
    delete ui;
}

void InstructionScreen::on_back_clicked()
{
//    dynamic_cast<QWidget*>(this->parent())->show();
    this->deleteLater();
}

void InstructionScreen::paintEvent(QPaintEvent *event)
{
    //Create the painter
    QPainter painter(this);

    //Draw background image
    QRect imageRect(0,0,this->width(), this->height());
    painter.drawImage(imageRect, bg);

    painter.end();
}
